package com.contest;

import com.contest.entity.RaceInfo;
import com.contest.util.DateUtil;
import redis.clients.jedis.Jedis;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SimpleCORSFilter implements Filter {

    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
                         FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
        chain.doFilter(req, res);

    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {

    }

    public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.1.254", 6379);
        System.out.println(jedis.set(DateUtil.now(), "125473"));
        System.out.println(jedis.expire(DateUtil.now(), 60 * 60 * 24));
        System.out.println(jedis.hset("王者荣耀", DateUtil.now(), "235847"));
        System.out.println(jedis.hget("王者荣耀", DateUtil.now()));
        jedis.close();
    }
}
